package PartsLookUp;

import java.sql.*;

/**
 * Created with IntelliJ IDEA.
 * User: Jason
 * Date: 8/15/13
 * Time: 3:10 PM
 * To change this template use File | Settings | File Templates.
 */
public class dnkNumToPL {

    int found=0;
    String plNum="";
    String dnkNum ="";

    public dnkNumToPL(String a) {
        dnkNum=a;

        //To change body of created methods use File | Settings | File Templates.
    }

    public String getNum(){
        
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String dataSourceName = "dbLI";
            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
            Connection con = DriverManager.getConnection(dbURL, "", "");
            Statement sta = con.createStatement();
            try {

                    String selecSta ="SELECT * from tblinventory where [part#]='"+dnkNum+"'";
                    sta.execute(selecSta);
                    ResultSet resultSet = sta.getResultSet();

//                System.out.println(dnkNum);
//                System.out.println(plNum);


                    if (resultSet != null)  {
                        while (resultSet.next()) {
                            plNum=resultSet.getString("PARTSLINK");
                            found++;
                            if (found==1){
//                                System.out.println("Found 1");
                            }else if (found>1){
//                                System.out.println("Multiple item with PL found for DNK#:"+dnkNum);
                            }                                   
                            
                        }
                    }

            }catch (SQLException s){
//                System.out.println(s);
            }
            con.close();
            sta.close();
        }
        catch (ClassNotFoundException c){}
        catch (SQLException c1){}
        
    return plNum;
    }
}
